package com.rcadmin.core.web;

import javax.annotation.Resource;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.rcadmin.common.prop.FileResProp;
import com.rcadmin.common.prop.OnlineResProp;
import com.rcadmin.common.prop.TemplateResProp;

@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
	@Resource
	private FileResProp fileResProp;
	@Resource
	private TemplateResProp templateResProp;
	@Resource
	private OnlineResProp onlineResProp;

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		set4PrjInnerResource(registry);
		set4OuterResource(registry);
	}

	private void set4PrjInnerResource(ResourceHandlerRegistry registry) {
		// 设置项目相关资源
		registry.addResourceHandler("/admin/*").addResourceLocations(
				"classpath:/static/");
	}

	/**
	 * 设置外部资源
	 * 
	 * @param registry
	 */
	private void set4OuterResource(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/" + fileResProp.getUrlPrefix() + "/**")
				.addResourceLocations("file:///" + fileResProp.getUploadDir());
		registry.addResourceHandler(
				"/" + templateResProp.getUrlPrefix() + "/**")
				.addResourceLocations(
						"file:///" + templateResProp.getUploadDir());
		registry.addResourceHandler("/" + onlineResProp.getUrlPrefix() + "/**")
				.addResourceLocations("file:///" + onlineResProp.getUploadDir());

	}
}
